#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<vector<int>> ret;
    void recursion(vector<int>& nums, vector<int>& visit, vector<int>& v, int level)
    {
        for (int i = 0;i < nums.size();++i)
        {
            if (visit[i] == 0)
            {
                if (i > 0 && nums[i] == nums[i - 1] && visit[i - 1] == 0) continue;
                v.push_back(nums[i]);
                if (v.size() == nums.size())
                {
                    ret.push_back(v);
                    v.pop_back();
                    continue;
                }
                visit[i] = 1;
                if (level + 1 <= nums.size())
                    recursion(nums, visit, v, level + 1);
                v.pop_back();
                visit[i] = 0;
            }
        }
        return;
    }
    vector<vector<int>> permuteUnique(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());
        int n = nums.size();
        vector<int> visit(n, 0);
        vector<int> v;
        recursion(nums, visit, v, 1);
        return ret;
    }
};